﻿using ProjectSemIII.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ProjectSemIII.Administrator.Process
{
    public class AccountProcess
    {
        private project_sem3Entities projectEntity;
        public AccountProcess()
        {
            projectEntity = new project_sem3Entities();
        }
        //Get all account pending
        public List<User> getAllAccountByStatus(int status)
        {
            List<User> listUser;
            try
            {
                listUser = (from u in projectEntity.Users
                            where u.Actived == status
                            select u).ToList();
            }
            catch
            {
                listUser = new List<User>();
            }
            return listUser;
        }

        //Accept or decline user function
        public int updateStatusUser(int userID, int status)
        {
            try
            {
                User user = (from u in projectEntity.Users
                             where u.UserID == userID
                             where u.Actived == 0
                             select u).Single();
                user.Actived = status;
                projectEntity.SaveChanges();
                return 10;
            }
            catch
            {
                return 100;
            }
        }

        public List<string> getDataAutoComplate(string user)
        {
            List<string> result = (from u in projectEntity.Users
                                   where u.Username.Contains(user)
                                   select u.Username).ToList();
            return result;
        }

        //Delete user by user id function
        public int deleteUserByUserID(int userID)
        {
            try
            {
                User user = (from u in projectEntity.Users
                             where u.UserID == userID
                             select u).Single();
                projectEntity.Users.Remove(user);
                projectEntity.SaveChanges();
                return 10;
            }
            catch
            {
                return 100;
            }
        }
    }
}